<template>
    <h4>学习teleport</h4>
    <button @click="toggle">打开/关闭 弹窗</button>
    <Teleport to="body">
        <div v-if="show" class="mask">
            <div class="dialog">
                <h4>这是一个弹窗</h4>
                <h5>内容~~~~~</h5>
                <h5>内容~~~~~</h5>
                <h5>内容~~~~~</h5>
            </div>
        </div>
    </Teleport>
</template>

<script>
import { ref } from 'vue';

export default {
    name: 'StudyTeleport',
    setup() {
        let show = ref(false)

        function toggle() {
            show.value = !show.value
        }

        return {
            show,
            toggle
        }
    }
}
</script>

<style>
    .mask{
        position: absolute;
        top: 0; bottom:0; left: 0; right: 0;
        background-color: rgba(0, 0, 0, 0.5);
    }
    .dialog{
        position: absolute;
        top: 50%;
        left: 50%;
        transform: translate(-50%, -50%); /*  */
        text-align: center;
        width: 300px;
        height: 300px;
        background-color: green;
    }
</style>